package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.MouseEvent;
	import flash.geom.ColorTransform;
	import flash.geom.Matrix;
	import flash.globalization.Collator;
	
	public class MaxBitmap extends Sprite
	{
		[Embed(source="b.png")]
		private static var _bmd:Class;
		private const count:int = 5;
		private var container:Sprite;
		public function MaxBitmap()
		{
			super();
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			container = new Sprite();
			addChild(container);
			var a:DisplayObject = new _bmd();
			
			for(var j:int = 0;j<1;j++)
			{
				var bmp:Bitmap = new Bitmap();
				try
				{
					var bmd:BitmapData = new BitmapData(a.width*count,a.height*count);
				}
				catch(e:Error)
				{
					throw new Error("wrong",a.width)
				}
				for(var i:int = 0;i<count ;i++)
				{
					var mtx:Matrix = new Matrix();
					mtx.tx = i* a.width;
						var cfm:ColorTransform = new ColorTransform(1*i,0,0,0,0,0,0,0);
				//	var cfm:ColorTransform = new ColorTransform();
					bmd.draw(a,mtx,cfm);
					for(var m:int = 0;m<bmd.width;m++)
					{
						var find:Boolean = false;
						for(var k:int = 0;k < bmd.height;k++)
						{
							if(bmd.getPixel(m,k).toString(16)!="ffffff")
							{
								trace("count",i,"finded",m,k,bmd.getPixel(m,k).toString(16));
								find = true;
								break;
							}
						}
						if(find)
							break;
						
					}
					
					
				}
				
				bmp.x = j*a.width*10;
				bmp.bitmapData = bmd;
				//bmd.dispose();
				container.addChild(bmp)
			}
			trace(bmd.width)
			
			trace(container.width)
			
			container.addEventListener(MouseEvent.MOUSE_DOWN,onDown,false,0,true);
		}
		
		private function onDown(evt:MouseEvent):void
		{
			container.startDrag();
			//stage.addEventListener(MouseEvent.MOUSE_MOVE,onMove,false,0,true),
			stage.addEventListener(MouseEvent.MOUSE_UP,onUp,false,0,true);	
		}
		
		private function onUp(evt:MouseEvent):void
		{
			container.stopDrag();
		}
	}
}